Jx.declare('Jx.event.Observable', {

	$requires: [

		'Jx.event.Dispatcher'

	],

	event: undefined,

	eventClass: 'Jx.event.Dispatcher',

	constructor: function(){

		var J = Jx;

		this.event = J.instantiate(

			J.resolveClassName( this.eventClass, 'Jx.event.Dispatcher' ),

			[ this ]

		);

		this.$super(arguments);

	},

	onDestroy: function(){

		Jx.destruct(this.event);

		this.$super(arguments);

	},

	onBeforeDestroy: function(){

	},

	destroy: function(){

		// at this point observable must call before destroy
		if (!this.destroyed && !this.destroying){

			this.event.dispatch('beforedestroy');

			this.onBeforeDestroy();

			this.event.dispatch('destroy');

		}

		return this.$super(arguments);

	}


});
